<?php
	require_once 'baza.inc.php';
	
	$q = $db->prepare("SELECT * FROM mjerenje");
	$q->execute();
	
	$boja_hex = array('000000', '00FF00', '33FF00', '66FF00', '99FF00', 'CCFF00', 'FFFF00', 'FFCC00', 'FF9900', 'FF6600', 'FF3300', 'FF0000', '00FF00');
	
	function odredi_boju($plin, $kolicina) {
		switch ($plin) {
			case 'O3': $gv=120; break;
			case 'CO': $gv=10000; break;
			case 'NO2': $gv=80; break;
			case 'VOC': $gv=50; break;
		} 
			
		$boja = round ($kolicina / ($gv / 11));
		if ($boja < 1) $boja=1;
		if ($boja > 11) $boja=11;
		return $boja;
	}
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	echo "<markers>\n";
	
	foreach ($q as $red){
		echo "\t<marker";
		echo " lat=\"" . $red['latitude'];
		echo "\" lng=\"" . $red['longitude'];
		echo "\" time=\"" . $red['vrijeme'];
		echo "\" O3=\"" . $red['kolicinaO3'];
		echo "\" CO=\"" . $red['kolicinaCO'];
		echo "\" NO2=\"" . $red['kolicinaNO2'];
		echo "\" VOC=\"" . $red['kolicinaVOC'];
		echo "\" O3col=\"" . $boja_hex[odredi_boju('O3', $red['kolicinaO3'])];
		echo "\" COcol=\"" . $boja_hex[odredi_boju('CO', $red['kolicinaCO'])];
		echo "\" NO2col=\"" . $boja_hex[odredi_boju('NO2', $red['kolicinaNO2'])];
		echo "\" VOCcol=\"" . $boja_hex[odredi_boju('VOC', $red['kolicinaVOC'])];
		echo "\" icon=\"" . $boja_hex[max(odredi_boju('O3', $red['kolicinaO3']), odredi_boju('CO', $red['kolicinaCO']), odredi_boju('NO2', $red['kolicinaNO2']), odredi_boju('VOC', $red['kolicinaVOC']))];
		echo "\" />\n";
	}
	
	echo '</markers>';
	
	
?>


